﻿using System;
using System.Windows.Controls;
using Microsoft.Phone.Shell;
using Microsoft.Phone.Controls;
using Com.PhilChuang.Pmvp.Ui.Views.Impl.ViewModels;

namespace Com.PhilChuang.Pmvp.Ui.Views.Impl.Pages
{
	public sealed partial class SendFeedbackPage
	{
		#region Events
		public event Action DoSendEmail = delegate { };
		#endregion

		#region Instance members (EMPTY)
		#endregion

		#region Properties (EMPTY)
		#endregion

		#region Constructors / Init
		public SendFeedbackPage ()
		{
			InitializeComponent ();
			SetApplicationBarItems ();
		}
		#endregion

		#region Event handlers
		private void field_UserText_KeyUp (object sender, System.Windows.Input.KeyEventArgs e)
		{
			ViewModel.UserText = field_UserText.Text; // because TextBoxes don't normally update until they lose focus
		}

		private void field_UserText_TextChanged (object sender, TextChangedEventArgs e)
		{
			ViewModel.UserText = field_UserText.Text; // because TextBoxes don't normally update until they lose focus
		}

		private void g_btn_SendEmail_Click (object sender, EventArgs eventArgs)
		{
			DoSendEmail ();
		}
		#endregion

		#region Functionality
		public void FocusOnUserTextControl ()
		{
			field_UserText.Focus ();
		}
		#endregion

		#region Private methods
		protected override void SetApplicationBarItems ()
		{
			g_btn_SendEmail = (ApplicationBarIconButton) ApplicationBar.Buttons[0];
		}

		protected override bool UpdateApplicationBarItemsWhen (String propertyName)
		{
			return base.UpdateApplicationBarItemsWhen (propertyName)
				   || propertyName == INPCHelper.GetPropertyName (() => ViewModel.DoSendEmailEnabled);
		}

		protected override void UpdateApplicationBarItems ()
		{
			base.UpdateApplicationBarItems ();
			g_btn_SendEmail.IsEnabled = ViewModel.DoSendEmailEnabled;
		}
		#endregion

		#region Utility methods (EMPTY)
		#endregion
	}

	public class SendFeedbackPageBase : PageBase<SendFeedbackPageViewModel>
	{
	}
}
